package org.itboys.ace.web.lasted;

import org.itboys.admin.dto.lasted.SystemUserDto;
import org.itboys.admin.entity.lasted.SystemMenu;
import org.itboys.admin.service.lasted.SystemIndexService;
import org.itboys.admin.service.lasted.SystemUserService;
import org.itboys.admin.tools.AdminSessionHolder;
import org.itboys.framework.resource.ResourceHolder;
import org.itboys.framework.spring.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *作者：江雄
 * 描述：系统-首页
 * 时间：2017年2月24日.重新构建
 */
@RestController
public class AceSystemIndexController extends BaseController {

	/*@Autowired
	private AdminUserService adminUserService;*/
	@Autowired
	private SystemUserService userService;
	@Autowired
	private ResourceHolder resourceHolder;

	@Autowired
	private SystemIndexService indexService;



	/**
	 * 首页跳转
	 * 
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = { "/", ""})
	public ModelAndView index(HttpServletResponse response, Model model)
			throws Exception {

		if (AdminSessionHolder.getAdminUserId() == null) {
			return new ModelAndView("redirect:/admin/login");
			// response.sendRedirect(resourceHolder.getStringValue("adminLoginUrl"));
		} else {
			//过滤菜单
			List<SystemMenu> allowMenus=indexService.getUserAllowMenu(AdminSessionHolder.getAdminUserId());
			model.addAttribute("allowMenus", allowMenus);
			SystemUserDto systemUserDto = userService.findOne(AdminSessionHolder.getAdminUserId());
			model.addAttribute("systemUserDto", systemUserDto);
			return new ModelAndView(resourceHolder.getStringValue("adminIndexUrl"));
		}
	}

	@RequestMapping(value = { "/index/pre" })
	public ModelAndView index_pre(HttpServletResponse response, Model model)
			throws Exception {

		if (AdminSessionHolder.getAdminUserId() == null) {
			return new ModelAndView("redirect:/admin/login");
			// response.sendRedirect(resourceHolder.getStringValue("adminLoginUrl"));
		} else {
			/*//过滤菜单
			List<SystemMenu> allowMenus=indexService.getUserAllowMenu(AdminSessionHolder.getAdminUserId());
			model.addAttribute("allowMenus", allowMenus);
			SystemUserDto systemUserDto = userService.findOne(AdminSessionHolder.getAdminUserId());
			model.addAttribute("systemUserDto", systemUserDto);*/
			return new ModelAndView("index_pre");
		}
	}
	@RequestMapping("/sessiondelay")
	public ModelAndView sessionDelay(@RequestParam("type")String type){
		if(type.equals("0")){
			return new ModelAndView("session-delay");
		}else {
			return new ModelAndView("session-delay-index");
		}
	}

}
